package com.lsmo.android.carfans.activity.car;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lsmo.android.carfans.R;
import com.lsmo.android.carfans.app.widget.RemoteImageView;
import com.lsmo.android.carfans.model.car.BrandTypeThread;
import com.lsmo.android.util.ArrayListAdapter;

public class CarEvaluatListAdapter extends  ArrayListAdapter<BrandTypeThread>{

	public CarEvaluatListAdapter(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View localView1 = convertView;
		ViewHolder localViewHolder;
		LayoutInflater mInflater = ((Activity) mContext).getLayoutInflater();
		InputStream localInputStream;
		if(localView1 == null){
			localView1 = mInflater.inflate(R.layout.car_adapter_brandlist, null);
			localViewHolder = new ViewHolder();
			
			localViewHolder.title = (TextView)localView1.findViewById(R.id.brandname);
			localViewHolder.date = (TextView)localView1.findViewById(R.id.brandprice);
			localViewHolder.imageView = (RemoteImageView)localView1.findViewById(R.id.carbrandimage);
			
			localView1.setTag(localViewHolder);
		} else {
			localViewHolder = (ViewHolder) localView1.getTag();
		}
		
	    //图标
		try {
			AssetManager localAssetManager = this.mContext.getResources().getAssets();
	    	String str1 = ((BrandTypeThread)mList.get(position)).getImageName();
			localInputStream = localAssetManager.open(str1);
			String str2 = ((BrandTypeThread)mList.get(position)).getImageName();
			Drawable localDrawable = Drawable.createFromStream(localInputStream, str2);
			localViewHolder.imageView.setBackgroundDrawable(localDrawable);
			    
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//标题
		String titleString = ((BrandTypeThread)mList.get(position)).getEvaTitle();
		localViewHolder.title.setText(titleString);
		
		//发布时间+作者
		String dataTimeString = ((BrandTypeThread)mList.get(position)).getPublishDate();
		StringBuilder localStringBuilder = new StringBuilder(dataTimeString).append(" - ");
		String originString = ((BrandTypeThread)mList.get(position)).getOriginList();
		localViewHolder.date.setText(localStringBuilder.toString() + originString);
		
		return localView1;
	}


	class ViewHolder{
	    TextView date;
	    RemoteImageView imageView;
	    TextView title;
	}
}
